<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : listPost.xsl
    Created on : November 17, 2013, 5:33 PM
    Author     : Liem
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:p="http://xml.netbeans.org/schema/post" exclude-result-prefixes="p"
    version="1.0">
    <xsl:output method="html"/>
    <xsl:param name="pageId"></xsl:param>
    <xsl:param name="returnUrl"></xsl:param>
    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:template match="/">
        <div class="alert alert-info">
            <button type="button" class="close" onclick="">×</button>
            <i class="icon-info-sign"></i>
            You have
            <xsl:value-of select="count(//*[p:pageId=$pageId and p:status='Unread'])"/> new post(s)
        </div>
        <div class="post_list">
            <xsl:for-each select="//*[p:pageId=$pageId]">
                <xsl:sort select="p:id" order="descending" data-type="number"/>
                <div class="post_block clearfix">
                    <xsl:choose>
                        <xsl:when test="p:status='Unread'">
                            <xsl:attribute name="class">
                            post_block clearfix unread
                            </xsl:attribute>
                        </xsl:when>
                        <xsl:when test="p:status='Approved'">
                            <xsl:attribute name="class">
                            post_block clearfix approved
                            </xsl:attribute>
                        </xsl:when>
                        <xsl:when test="p:status='Read'">
                            <xsl:attribute name="class">
                            post_block clearfix read
                            </xsl:attribute>
                        </xsl:when>
                    </xsl:choose>
                    <h6>
                        <xsl:value-of select="p:postContent"/>
                    </h6>
                    <ul class="post_meta clearfix">
                        <li>
                            <span>
                            Date:
                                <xsl:value-of select="p:date"/>
                            </span>
                        </li>

                        <xsl:if test="p:status='Approved'">
                            <a href="#" target="_blank">
                                <xsl:attribute name="href">https://www.facebook.com/<xsl:value-of select="p:fbPostId"/>
                                </xsl:attribute>
                                View on Facebook
                            </a>
                        </xsl:if>
                    </ul>
                    <div class="btn-group pull-right">
                        <xsl:if test="p:status!='Approved'">
                            <a href="#" class="btn">
                                <xsl:attribute name="href">editPost.jsp?id=<xsl:value-of select="p:id"/>&amp;returnUrl=<xsl:value-of select="$returnUrl"/>
                                </xsl:attribute>
                                <i class="icon-edit"></i>Edit
                            </a>
                        </xsl:if>
                        <xsl:if test="p:status='Unread' or p:status='Read'">
                            <a class="btn">
                                <xsl:attribute name="href">approvePost.action?id=<xsl:value-of select="p:id"/>&amp;returnUrl=<xsl:value-of select="$returnUrl"/>
                                </xsl:attribute>
                                <i class="icon-ok" ></i>Approve
                            </a>
                        </xsl:if>
                        <xsl:if test="p:status='Unread'">
                            <a href="#" class="btn">
                                <xsl:attribute name="href">rejectPost.action?id=<xsl:value-of select="p:id"/>&amp;returnUrl=<xsl:value-of select="$returnUrl"/>
                                </xsl:attribute>
                                <i class=" icon-tag"></i>Mask as read
                            </a>
                        </xsl:if>
                        <xsl:if test="p:status='Approved'">
                            <a class="btn">
                                <xsl:attribute name="href">unpost.action?id=<xsl:value-of select="p:id"/>&amp;returnUrl=<xsl:value-of select="$returnUrl"/>
                                </xsl:attribute>
                                <i class="icon-remove-sign"></i>Unpost
                            </a>
                        </xsl:if>
                    </div>
                </div>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>
